﻿// My methods here.
//-----------------------------------------------------------------------
// <Copyright file=Web company=DHPD>
// Copyright (c) DHPD Corporation (http://dhpd.edu.vn). All rights reserved.
// </copyright>
// <author>HP</author>
//-----------------------------------------------------------------------


using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using KM.BUS;
using KM.ENT;
using KM.Models;
using CORE;

namespace KM.Areas.Admin.Controllers
{
    public class WebController : Controller
    {
        int pageSize = 20;
        
        public ActionResult dsWeb()
        {
            //lay danh sach loai san pham
            busWeb busW = new busWeb();
            List<entWeb> lst = new List<entWeb>();
            PagingInfoModel page = new PagingInfoModel()
            {
                CurrentPage = Utils.getIntQuery("page") == 0 ? 1 : Utils.getIntQuery("page"),
                recordPerPage = pageSize
            };
            lst = busW.getAll(ref page);
            ViewBag.page = page;
            return View(lst);
        }
        
        public ActionResult dsWebByForeignKey(int Id)
        {
            //lay danh sach loai san pham
            busWeb busW = new busWeb();
            List<entWeb> lst = new List<entWeb>();
            PagingInfoModel page = new PagingInfoModel()
            {
                CurrentPage = Utils.getIntQuery("page") == 0 ? 1 : Utils.getIntQuery("page"),
                recordPerPage = pageSize
            };
            lst = busW.getAllByForeignKey(Id, ref page);
            ViewBag.page = page;
            return View(lst);
        }
        
        public ActionResult edit(int Id = 0)
        {
            busWeb busW = new busWeb();
            entWeb entW = new entWeb();
            entW = busW.getInfo(Id);
            return View(entW);
        }
        
        public ActionResult delete(int Id)
        {
            busWeb busW = new busWeb();
            busW.delete(Id);
            return RedirectToAction("dsWeb", null, new { Id = 1 });
        }
        [HttpPost]
        
        [ValidateInput(false)]
        public ActionResult edit(entWeb entW)
        {
            if (!ModelState.IsValid)
            {
                return View(entW);
            }

            busWeb busW = new busWeb();
            busW.createEdit(entW);
            return RedirectToAction("edit", new { Id = entW.Id });


        }
        public PartialViewResult getLeftMenu(int Id)
        {
            busWeb busW = new busWeb();
            List<entWeb> lst = new List<entWeb>();
            lst = busW.getByIdParent(Id);
            
            return PartialView(lst);
        }
        public PartialViewResult getLeftMenuChid(int Id)
        {
            busWeb busW = new busWeb();
            List<entWeb> lst = new List<entWeb>();
            lst = busW.getByIdParent(Id);
            return PartialView(lst);
        }
    }
}
